package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.service.ILogService;
import com.briup.jz.utils.CustomerException;
import com.briup.jz.bean.BaseLog;
import com.briup.jz.bean.BaseLogExample;
import com.briup.jz.dao.BaseLogMapper;


@Service
public class BaseLogServiceImpl implements ILogService {
	
	@Autowired
	private BaseLogMapper baselogMapper;

	@Override
	public void save(BaseLog baselog) throws CustomerException {
		if(baselog.getId() ==null) {
			baselogMapper.insert(baselog);
		} else {
			// 判断是否有同名的分类，如果有抛出异常
			baselogMapper.updateByPrimaryKey(baselog);
//			//BaseLogExample example = new BaseLogExample();
//			example.createCriteria().andContentEqualTo(baselog.getRealname());
//			List<BaseLog> list = baselogMapper.selectByExample(example);
//			if(list.size()>0) {
//				throw new CustomerException("同名的分类已存在");
			}
		}
			
	@Override
	public List<BaseLog> query(Long id) {
		BaseLogExample example = new BaseLogExample();
		if(id!=null){
			example.createCriteria().andIdEqualTo(id);
		}
		List<BaseLog> list = baselogMapper.selectByExample(example);
		return list;
	}
}
